package com.abocode.aichat.app.utils;

import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by guanxf on 2015/12/16.
 */
public class ResourceUtils {
   public static  String getDateDir(){
       Date date = new Date();
       String path=new SimpleDateFormat("yyyy/MM/dd").format(date);
       return  path;
   }
   /***
　　　   获取文件名
    @param fileName
     * @return
    **/
    public static String getFileName(String fileName) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String realFilename=sdf.format(new Date())+StringUtil.getRandomSize8();
        String extend = ResourceUtils.getExtend(fileName, "");// 获取文件扩展名
        if(StringUtils.isEmpty(extend)){
             return  realFilename;
        }
        return realFilename+"."+extend;//自定义文件名称
    }

    /**
     * 获取文件扩展名
     *
     * @param filename
     * @return
     */
    public static String getExtend(String filename, String defExt) {
        if ((filename != null) && (filename.length() > 0)) {
            int i = filename.lastIndexOf('.');

            if ((i > 0) && (i < (filename.length() - 1))) {
                return (filename.substring(i+1)).toLowerCase();
            }
        }
        return defExt.toLowerCase();
    }
}
